<template>
  <div class="contioner">
    <div ref="myChart" :style="{ width: '100%', height: '100%' }"></div>
  </div>
</template>
      
  <script lang="ts" setup>
import * as echarts from 'echarts'
import { Message } from '@arco-design/web-vue'
import { ref, reactive, onMounted, watch } from 'vue'
//引入封装post
import { post } from '@/api/http'
import dayjs from 'dayjs'
//getlist初始化接口参数
let query: any = reactive({
  beginDate: dayjs().format('YYYY-MM-DD'), //当月日期
  enginDate: dayjs().format('YYYY-MM-DD'), //当月日期
    planOrderCode: localStorage.getItem('firmId') || '',
})
let state: any = null
window.addEventListener('resize', updateChartSize)
function updateChartSize() {
  state.resize()
}
const option = ref({
  title: {
    text: '订单准交率',
    /*textVerticalAlign:'center'*/
    top: '2%',
    left: '45%',
  },
  tooltip: {
    trigger: 'axis',
  },
  // legend: {
  //   data: ['本集团订单准交率', '外加工订单准交率', '厂部订单准交率'],
  //   top: '10%',
  //   right: '5%',
  // },
  grid: {
    left: '3%',
    right: '4%',
    bottom: '0%',
    containLabel: true,
  },
  xAxis: {
    type: 'category',
    boundaryGap: false,
    data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
  },
  yAxis: {
    type: 'value',
    axisLabel: {
      formatter: '{value} %',
      inside: false,
      // textStyle: {
      //   fontSize: '14',
      // },
      padding: [5, 0, 0, -5], //文字左右定位
    },
  },
  series: [
    {
      name: '本集团订单准交率',
      type: 'line',
      stack: 'Total',
      data: [120, 132, 101, 134, 90, 230, 120, 132, 101, 134, 90, 230],
      label: { show: true, position: 'top', distance: 10, formatter: '{c}%', fontSize: 16 },
    },
    {
      name: '外加工订单准交率',
      type: 'line',
      stack: 'Total',
      data: [220, 182, 191, 234, 290, 330, 310, 220, 182, 191, 234, 290],
      label: { show: true, position: 'top', distance: 10, formatter: '{c}%', fontSize: 16 },
    },
    {
      name: '厂部订单准交率',
      type: 'line',
      stack: 'Total',
      data: [150, 232, 201, 154, 190, 330, 410, 150, 232, 201, 154, 190],
      label: { show: true, position: 'top', distance: 10, formatter: '{c}%', fontSize: 16 },
    },
  ],
})

//初始化
onMounted(async () => {
  selectJt()
    // state = states()
  // state.setOption(option.value)
})
const myChart: any = ref()
const states = () => {
  return echarts.init(myChart.value)
}
function selectJt() {
  post({
    url: 'planSingle/report/orderCrossRate',
    data: {
      // "firmId": query.planOrderCode, //公司ID
      firmId: query.planOrderCode, //公司ID
      dateStart: query.beginDate,
      dateEnd: query.enginDate,
    },
  }).then((res: any) => {
    if (res.code == 200) {
      option.value.xAxis.data = res.data.map((e: any) => {
        return e.queryDate.split('-')[1] + '/' + e.queryDate.split('-')[2]
      })
      option.value.series[0].data = res.data.map((e: any) => {
        return e.bOrderCrossRate
      })
      option.value.series[1].data = res.data.map((e: any) => {
        return e.wOrderCrossRate
      })
      option.value.series[2].data = res.data.map((e: any) => {
        return e.orderCrossRate
      })
      state = states()
      state.setOption(option.value)
    } else {
      Message.error(res.message)
    }
  })
}
</script>
  <script lang="ts">
export default defineComponent({
  name: 'OrderFulfillmentrate',
})
</script>
  <style scoped>
.contioner {
  width: 100%;
  height: 100%;
  background: #fff;
  padding: 10px;
}

:deep(.ag-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-cell-value) {
  user-select: initial;
  -moz-user-select: text;
  -ms-user-select: text;
  -webkit-user-select: text;
}
</style>
      